import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

"""
generate the figure of the distribution of conf along the distance 
"""

# 设置matplotlib的全局参数以适应学术论文的需要
mpl.rcParams.update(
    {
        "font.size": 12,
        "figure.figsize": (8, 6),
        "figure.dpi": 300,
        "savefig.dpi": 1000,
        "lines.linewidth": 2,
        "legend.fontsize": "medium",
    }
)

# 假设的数据
# TCone+old_dataset
x1 = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
y1 = [0.94944, 0.94399, 0.84192, 0.84450, 0.60030, 0.63081, 0.57007, 0.41611, 0,0]

# YOLov5s+old_dataset
x2 = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
y2 = [0.95750, 0.93478, 0.88815, 0.849367, 0.67724, 0.57403, 0.14316, 0, 0,0]

# TCone+new_dataset
x3 = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
y3 = [0.96028, 0.95291,0.925973 , 0.90187, 0.89608, 0.8831, 0.86686, 0.8469, 0.673673,0.34502]

# 创建图形
plt.figure()

# 绘制折线图
plt.plot(x1, y1, label="TCone-YOLO with old dataset", marker="o", linestyle="-", color="blue")
plt.plot(x2, y2, label="YOLOV5s with old datase", marker="s", linestyle="-", color="green")
plt.plot(x3, y3, label="TCone-YOLO with new dataset", marker="^", linestyle="-", color="red")

# 添加图表标题和轴标签
# plt.title("Confidence Levels at Different Distances")
plt.xlabel("Distance (m)")
plt.ylabel("Confidence")


# X轴刻度设置
all_x_ticks = sorted(set(x1 + x2))  # 合并两组数据的X轴数据，并去重排序
plt.xticks(all_x_ticks)  # 设置X轴刻度显示所有点的x值

# Y轴范围设置
plt.yticks(np.linspace(0, 1, 11))  # 从0到1，分成10段

# 网格线
plt.grid(True, linestyle="--", linewidth=0.5)

# 添加图例
plt.legend()

# 保存图形为高清PNG文件
plt.savefig("plot_3.png", format="png", bbox_inches="tight")

# 显示图形
plt.show()
